package com.example.carRental.service.impl;

import com.example.carRental.entity.Car;
import com.example.carRental.entity.Charterer;
import com.example.carRental.entity.User;
import com.example.carRental.mapper.CarMapper;
import com.example.carRental.mapper.ChartererMapper;
import com.example.carRental.service.ChartererService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 92307
 * @version 1.0
 * @time 2022/3/24
 * @Describe describe
 */
@Service
public class ChartererServiceImpl implements ChartererService {
    @Resource
    private ChartererMapper chartererMapper;
    @Resource
    private CarMapper carMapper;
//    @Resource
//    private

    @Override
    public void addCar(Car car) {
        car.setChartererId(User.getUserId());
        carMapper.insert(car);
    }

    @Override
    public Charterer getInfo() {
        System.out.println(User.getUserId());
        return chartererMapper.selectById(User.getUserId());
    }


    @Override
    public List<Car> getCarList() {
        List<Car> allCar = carMapper.getCarByCId(User.getUserId());
        for (Car car : allCar) {
            car.setChartererName(chartererMapper.getNameById(car.getChartererId()));
            car.setImage(carMapper.getPictures(car.getId()));
        }
        return allCar;
    }

    @Override
    public String getNameById(Integer chartererId) {
        return chartererMapper.getNameById(chartererId);
    }

    @Override
    public Charterer getByName(String name) {

        return null;
    }



}
